#!/bin/gawk -f
# add residue names to an Aqua restraint files having only "UNK"
# argument: pdb=file, where 'file' is the name of a PDB file from which
# the residue names are obtained

BEGIN {
    if ( pdb == "" ) {
	print "usage: addresnam pdb=file1 file2"
	print "    file1: name of PDB file from which residue names are obtained"
	print "    file2: name of Aqua restraint file to be converted"
	exit( 1 )
    }
    while ( getline < pdb ) {
	if ( $1 == "ATOM" )
	    res[$5] = $4
    }
    close( pdb )
}

NR <3 {
    print $0
    next
}

/^#/ { next }

{
....check residue name
....replace if UNK
}


